'''
@author: pnuzhnyi
'''

from django.core.exceptions import ObjectDoesNotExist
from surfers.models import Surfer

class surfer_repository():
    def __init__(self):
        pass
    
    def get_or_create_surfer(self, fbook_id):
        try:
            return Surfer.objects.get(fbook_id=fbook_id)
        except ObjectDoesNotExist:
            newSurfer = Surfer()
            newSurfer.fbook_id = fbook_id
            newSurfer.stats = {"experience":0,"level": 1,"strength": 10, "stamina": 5,"fame": 0,"cash": 5000}
            newSurfer.save()
            return newSurfer
        
    def update_surfer(self, surfer):
        surfer.save()

    def boost_stats(self, surfer, booster):
        stats = surfer.stats
        
        for (k, v) in booster.items():
            if stats.has_key(k): stats[k] = stats[k] + v
            else: stats[k] = v
            
        surfer.stats = stats
        surfer.save()